<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>测试vue生命周期函数</title>
	</head>
	<body>
		<div id="app">
			<h1>前后端调用测试</h1>
		</div>
		
		<script src="../js/axios.js"></script>
		<script>
			/**
			 *  完成用户入库操作
			 *  用法: axios.post(url地址,对象名称)
			 * 	      axios.put(url地址, 对象名称)
			 * 
			 * 		  axios.get(url地址,{params: 对象名称})
			 * 		  axios.delete(url地址,{params: 对象名称})
			 */
			
			//定义axios请求的前缀
			axios.defaults.baseURL = "http://localhost:8090"
			//let url1 = "/axios/saveUser"
			let user1 = {name: "tomcat",age: 18, sex: "女"}
			axios.post("/axios/saveUser",user1)
				.then(function(promise){
					//动态获取状态信息
					let status = promise.status
					/* if(status === 200){
						alert(promise.data)
					}else{
						alert("用户新增失败")
					} */
					console.log(promise)
					console.log(promise.data)
				})
			
			/**
			 * ajax嵌套 
			 */
			/* axios.post("/axios/saveUser2",user1)
				 .then(function(promise){
					 let result = promise.data
					 //根据返回值结果,当做参数再次发起ajax请求
					 axios.post("/axios/saveUser3",result)
						  .then(function(promise){
							  //..............
							  console.log(promise.data)
						  })
				 }) */
				 
				 
				/**
				 * 1.定义一个方法
				 * 关键字: 
				 * 		1. async 标识函数
				 *      2. await 标识ajax请求
				 */
				async function saveUser(){
					let user2 = {name: "axios",age: 18, sex: "男"}
					//let {conf: confv,data: datav,status: statusv} = await axios.post("/axios/saveUser",user2)
					let {data: result} = await axios.post("/axios/saveUser",user2)
					console.log(result)
				}
				 
				//2.调用方法
				saveUser()
				 
				 
		</script>
		
		
	</body>
</html>